﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProDivingAdmin2salmon14
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            
            ContestData cd = new ContestData();
            DiverForm diverForm = new DiverForm();
            StartUpForm startUpForm = new StartUpForm();
            AddDataForm addDataForm = new AddDataForm();
            startUpForm.FormClosed += new FormClosedEventHandler(OnStartUpClose);

            FormMain form = new FormMain(startUpForm, diverForm, addDataForm);
            Contest emptyContest = new Contest();

            FormMainPresenter presenter = new FormMainPresenter(form, startUpForm, diverForm, addDataForm, cd, emptyContest, emptyContest.diverList);
            try
            {
                CommunicationServer.SetupServer();
                Application.Run(form);
            }
            catch (TargetInvocationException e) 
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine(e.InnerException);
                Application.Exit();
            }
            //System.Windows.Forms.DialogResult result = startUpForm.ShowDialog();
            //if (result == System.Windows.Forms.DialogResult.OK)
            //{
            //    FormMain form = new FormMain();
            //    Contest contest = new Contest(cd.isFemale, cd.minAge, cd.divingHeight, cd.judges, cd.diversPath, cd.judgesPath);

            //    FormMainPresenter presenter = new FormMainPresenter(form, contest, contest.diverList);

            //    Application.Run(form);
            //}
            //else
            //{
            //    MessageBox.Show("Closing ProDivingAdmin2salmon14");
            //    Application.Exit();
            //}
        }

        private static void OnStartUpClose(object sender, FormClosedEventArgs e)
        {
            
        }
    }
}
